{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Check that the RGI entitites can be attributed to the correct region and sub-region "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is the first of a series of 3 similar notebooks. This one demonstrates the problem."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "rgi_version = '60'\n",
    "out_dir = 'RGI62_update_logs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import geopandas as gpd\n",
    "import shapely.geometry as shpg\n",
    "import progressbar\n",
    "import os\n",
    "import numpy as np\n",
    "from oggm import utils, cfg\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/mowglie/Documents/git/rgitools/notebooks/rgi_60_corrections/RGI62_update_logs'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "out_dir = os.path.abspath(out_dir)\n",
    "utils.mkdir(out_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# The RGI megafile\n",
    "out = []\n",
    "for reg in range(1, 20):\n",
    "    sh = gpd.read_file(utils.get_rgi_region_file('{:02d}'.format(reg), version=rgi_version)).set_index('RGIId')\n",
    "    out.append(sh)\n",
    "mdf =  pd.concat(out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add Point geometries for faster checks\n",
    "mdf['points'] = [shpg.Point(lon, lat) for (lon, lat) in zip(mdf.CenLon, mdf.CenLat)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "rgi_reg = gpd.read_file(os.path.join(utils.get_rgi_dir(rgi_version), '00_rgi60_regions', '00_rgi60_O1Regions.shp'))\n",
    "rgi_sreg = gpd.read_file(os.path.join(utils.get_rgi_dir(rgi_version), '00_rgi60_regions', '00_rgi60_O2Regions.shp'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "rgi_reg['RGI_CODE'] = [str(s) for s in rgi_reg.RGI_CODE]  # this won't be necessary with the corrected file\n",
    "mdf['RGI_CODE'] = ['{:02d}-{:02d}'.format(int(d1), int(d2)) for (d1, d2) in zip(mdf.O1Region, mdf.O2Region)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.testing.assert_equal(mdf['O1Region'].unique(), rgi_reg['RGI_CODE'].unique())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": []
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": []
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": []
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100% (27108 of 27108) |#######| Elapsed Time: 0:00:21 Time:  0:00:21 RGI Reg: 1\n",
      "100% (18855 of 18855) |#######| Elapsed Time: 0:00:15 Time:  0:00:15 RGI Reg: 2\n",
      "100% (4556 of 4556) |#########| Elapsed Time: 0:00:01 Time:  0:00:01 RGI Reg: 3\n",
      "100% (7415 of 7415) |#########| Elapsed Time: 0:00:02 Time:  0:00:02 RGI Reg: 4\n",
      "100% (20261 of 20261) |#######| Elapsed Time: 0:00:05 Time:  0:00:05 RGI Reg: 5\n",
      "100% (568 of 568) |###########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 6\n",
      "100% (1615 of 1615) |#########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 7\n",
      "100% (3417 of 3417) |#########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 8\n",
      "100% (1069 of 1069) |#########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 9\n",
      "100% (5151 of 5151) |########| Elapsed Time: 0:00:01 Time:  0:00:01 RGI Reg: 10\n",
      "100% (3927 of 3927) |########| Elapsed Time: 0:00:01 Time:  0:00:01 RGI Reg: 11\n",
      "100% (1888 of 1888) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 12\n",
      "100% (54429 of 54429) |######| Elapsed Time: 0:00:47 Time:  0:00:47 RGI Reg: 13\n",
      "100% (27988 of 27988) |######| Elapsed Time: 0:00:16 Time:  0:00:16 RGI Reg: 14\n",
      "100% (13119 of 13119) |######| Elapsed Time: 0:00:09 Time:  0:00:09 RGI Reg: 15\n",
      "100% (2939 of 2939) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 16\n",
      "100% (15908 of 15908) |######| Elapsed Time: 0:00:04 Time:  0:00:04 RGI Reg: 17\n",
      "100% (3537 of 3537) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 18\n",
      "100% (2752 of 2752) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI Reg: 19\n"
     ]
    }
   ],
   "source": [
    "mdf['NOT_IN_REG'] = False\n",
    "mdf['NEW_REG'] = ''\n",
    "for reg in mdf['O1Region'].unique():\n",
    "    sel = rgi_reg[rgi_reg.RGI_CODE == reg]\n",
    "    mdf_sel = mdf.loc[mdf.O1Region == reg]\n",
    "    for rid, p, g in progressbar.progressbar(zip(mdf_sel.index, mdf_sel.points, mdf_sel.geometry), \n",
    "                                             max_value=len(mdf_sel), suffix= ' RGI Reg: ' + reg):\n",
    "        if not np.sum(sel.contains(p)) > 0:\n",
    "            if not np.sum(sel.intersects(g)) > 0:\n",
    "                mdf.loc[rid, 'NOT_IN_REG'] = True\n",
    "                \n",
    "                cc = rgi_reg.loc[rgi_reg.contains(p)]\n",
    "                if len(cc) == 0:\n",
    "                    pass\n",
    "                elif len(cc) == 1:\n",
    "                    mdf.loc[rid, 'NEW_REG'] = cc.iloc[0].RGI_CODE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "misplaced = mdf.loc[mdf.NOT_IN_REG & mdf.NEW_REG]\n",
    "print(len(misplaced))\n",
    "not_ok = mdf.loc[mdf.NOT_IN_REG & (mdf.NEW_REG == '')]\n",
    "print(len(not_ok))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "tw = not_ok.copy().drop(['points', 'NOT_IN_REG'], axis=1).reset_index(level=0)\n",
    "odir = utils.mkdir(os.path.join(out_dir, 'entities_without_region'))\n",
    "tw.to_file(os.path.join(odir, 'no_reg.shp'))\n",
    "\n",
    "tw = misplaced.copy().drop(['points', 'NOT_IN_REG'], axis=1).reset_index(level=0)\n",
    "odir = utils.mkdir(os.path.join(out_dir, 'entities_misplaced'))\n",
    "tw.to_file(os.path.join(odir, 'reg_misplaced.shp'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100% (5780 of 5780) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 01-02\n",
      "100% (10551 of 10551) || Elapsed Time: 0:00:08 Time:  0:00:08 RGI SUBREG: 01-06\n",
      "100% (4258 of 4258) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 01-04\n",
      "100% (616 of 616) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 01-01\n",
      "100% (872 of 872) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 01-03\n",
      "100% (5031 of 5031) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 01-05\n",
      "100% (3202 of 3202) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 02-04\n",
      "100% (7387 of 7387) |##| Elapsed Time: 0:00:02 Time:  0:00:02 RGI SUBREG: 02-02\n",
      "100% (5064 of 5064) |##| Elapsed Time: 0:00:03 Time:  0:00:03 RGI SUBREG: 02-03\n",
      "100% (1967 of 1967) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 02-05\n",
      "100% (1235 of 1235) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 02-01\n",
      "100% (880 of 880) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 03-03\n",
      "100% (627 of 627) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 03-02\n",
      "100% (525 of 525) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 03-05\n",
      "100% (227 of 227) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 03-06\n",
      "100% (2049 of 2049) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 03-01\n",
      "100% (241 of 241) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 03-04\n",
      "100% (7 of 7) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 03-07\n",
      "100% (1108 of 1108) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-07\n",
      "100% (71 of 71) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-02\n",
      "100% (65 of 65) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-08\n",
      "100% (1645 of 1645) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-05\n",
      "100% (2249 of 2249) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-06\n",
      "100% (1442 of 1442) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-04\n",
      "100% (277 of 277) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-03\n",
      "100% (455 of 455) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-01\n",
      "100% (103 of 103) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 04-09\n",
      "100% (20261 of 20261) || Elapsed Time: 0:00:05 Time:  0:00:05 RGI SUBREG: 05-01\n",
      "100% (568 of 568) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 06-01\n",
      "100% (1567 of 1567) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 07-01\n",
      "100% (48 of 48) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 07-02\n",
      "100% (1837 of 1837) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 08-01\n",
      "100% (365 of 365) |####| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 08-03\n",
      "100% (1215 of 1215) |##| Elapsed Time: 0:00:06 Time:  0:00:06 RGI SUBREG: 08-02\n",
      "100% (480 of 480) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 09-02\n",
      "100% (177 of 177) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 09-03\n",
      "100% (412 of 412) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 09-01\n",
      "100% (481 of 481) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 10-02\n",
      "100% (447 of 447) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 10-03\n",
      "100% (161 of 161) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 10-01\n",
      "100% (2437 of 2437) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 10-04\n",
      "100% (1581 of 1581) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 10-05\n",
      "100% (44 of 44) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 10-06\n",
      "100% (3892 of 3892) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 11-01\n",
      "100% (35 of 35) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 11-02\n",
      "100% (1637 of 1637) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 12-01\n",
      "100% (251 of 251) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 12-02\n",
      "100% (5397 of 5397) |##| Elapsed Time: 0:00:02 Time:  0:00:02 RGI SUBREG: 13-05\n",
      "100% (5065 of 5065) |##| Elapsed Time: 0:00:02 Time:  0:00:02 RGI SUBREG: 13-09\n",
      "100% (9368 of 9368) |##| Elapsed Time: 0:00:06 Time:  0:00:06 RGI SUBREG: 13-08\n",
      "100% (5227 of 5227) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 13-04\n",
      "100% (9739 of 9739) |##| Elapsed Time: 0:00:03 Time:  0:00:03 RGI SUBREG: 13-03\n",
      "100% (10233 of 10233) || Elapsed Time: 0:00:04 Time:  0:00:04 RGI SUBREG: 13-02\n",
      "100% (3151 of 3151) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 13-01\n",
      "100% (3519 of 3519) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 13-06\n",
      "100% (2730 of 2730) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 13-07\n",
      "100% (13757 of 13757) || Elapsed Time: 0:00:07 Time:  0:00:07 RGI SUBREG: 14-02\n",
      "100% (9830 of 9830) |##| Elapsed Time: 0:00:05 Time:  0:00:05 RGI SUBREG: 14-03\n",
      "100% (4401 of 4401) |##| Elapsed Time: 0:00:02 Time:  0:00:02 RGI SUBREG: 14-01\n",
      "100% (4353 of 4353) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 15-03\n",
      "100% (4238 of 4238) |##| Elapsed Time: 0:00:03 Time:  0:00:03 RGI SUBREG: 15-02\n",
      "100% (4528 of 4528) |##| Elapsed Time: 0:00:02 Time:  0:00:02 RGI SUBREG: 15-01\n",
      "100% (2891 of 2891) |##| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 16-01\n",
      "100% (7 of 7) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 16-02\n",
      "100% (36 of 36) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 16-03\n",
      "100% (5 of 5) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 16-04\n",
      "100% (6474 of 6474) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 17-02\n",
      "100% (9434 of 9434) |##| Elapsed Time: 0:00:02 Time:  0:00:02 RGI SUBREG: 17-01\n",
      "100% (3537 of 3537) |##| Elapsed Time: 0:00:01 Time:  0:00:01 RGI SUBREG: 18-01\n",
      "100% (667 of 667) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-20\n",
      "100% (169 of 169) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-21\n",
      "100% (123 of 123) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-19\n",
      "100% (121 of 121) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-15\n",
      "100% (34 of 34) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-16\n",
      "100% (20 of 20) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-18\n",
      "100% (162 of 162) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-11\n",
      "100% (73 of 73) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-13\n",
      "100% (70 of 70) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-14\n",
      "100% (14 of 14) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-24\n",
      "100% (5 of 5) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-22\n",
      "100% (109 of 109) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-17\n",
      "100% (15 of 15) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-05\n",
      "100% (412 of 412) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-02\n",
      "100% (1 of 1) |########| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-12\n",
      "100% (27 of 27) |######| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-01\n",
      "100% (553 of 553) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-03\n",
      "100% (177 of 177) |####| Elapsed Time: 0:00:00 Time:  0:00:00 RGI SUBREG: 19-04\n"
     ]
    }
   ],
   "source": [
    "mdf['NOT_IN_SREG'] = False\n",
    "mdf['NEW_SREG'] = ''\n",
    "for sreg in mdf['RGI_CODE'].unique():\n",
    "    sel = rgi_sreg[rgi_sreg.RGI_CODE == sreg]\n",
    "    mdf_sel = mdf.loc[mdf.RGI_CODE == sreg]\n",
    "    for rid, p, g in progressbar.progressbar(zip(mdf_sel.index, mdf_sel.points, mdf_sel.geometry), \n",
    "                                             max_value=len(mdf_sel), suffix= ' RGI SUBREG: ' + sreg):\n",
    "        if not np.sum(sel.contains(p)) > 0:\n",
    "            if not np.sum(sel.intersects(g)) > 0:\n",
    "                mdf.loc[rid, 'NOT_IN_SREG'] = True\n",
    "                \n",
    "                cc = rgi_sreg.loc[rgi_sreg.contains(p)]\n",
    "                if len(cc) == 0:\n",
    "                    pass\n",
    "                elif len(cc) == 1:\n",
    "                    mdf.loc[rid, 'NEW_SREG'] = cc.iloc[0].RGI_CODE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "142\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "misplaced = mdf.loc[mdf.NOT_IN_SREG & mdf.NEW_SREG]\n",
    "print(len(misplaced))\n",
    "not_ok = mdf.loc[mdf.NOT_IN_SREG & (mdf.NEW_SREG == '')]\n",
    "print(len(not_ok))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "tw = not_ok.copy().drop(['points', 'NOT_IN_REG', 'NOT_IN_SREG'], axis=1).reset_index(level=0)\n",
    "odir = utils.mkdir(os.path.join(out_dir, 'entities_without_region'))\n",
    "tw.to_file(os.path.join(odir, 'no_subreg.shp'))\n",
    "\n",
    "tw = misplaced.copy().drop(['points', 'NOT_IN_REG', 'NOT_IN_SREG'], axis=1).reset_index(level=0)\n",
    "odir = utils.mkdir(os.path.join(out_dir, 'entities_misplaced'))\n",
    "tw.to_file(os.path.join(odir, 'subreg_misplaced.shp'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAELCAYAAADURYGZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAEmxJREFUeJzt3X+8ZHVdx/HXW1YSLALcjRDMJcQMzSI2sygt8FFoCWRm+khFw0hDzLSSokea5aMUsxDsxwYYmPmLNLHMUiItU2xXKGApBETF+LGZppmZa5/+mO9tZ5fde2f3zpm5d7+v5+Mxj53za857Z+be9z3nzDmTqkKS1K97zTuAJGm+LAJJ6pxFIEmdswgkqXMWgSR1ziKQpM5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EItC+7gtV9S1V9TBGV4Q8C6D94v1zYGNVHV1VxwNnMzqhZ0lJHgs8H/i+qvomRmfW/kebfBbwncA3V9WDGZ2odsXCL/vme9tyj2jr/P2xabe0zAu3y/buvy5NZi7fWSzNyQeAh7f7PwZ8oKquWJhYVdczOgt2Er8A/GxV/Wtb9ovAH7RpLwIeXe3SxlX1V0n+vq3z4vEHqar/TPJs4BNJDt27/5a0PG4RqAtJ9gNOAhZ+8T+U0WUP9tbDgM27WM9BwH2r6tadJm1q67yHGl1r/qNsv6jh0TvtGvruZeSUluQWgfZ1ByS5ltF13W9kdHnpe0jyNka/iG+qqifMMN//Rxi7f0tVfcscMqhTbhFoX/eF9kv1gYx+2Z7Vxt/A6OsEAaiqH2L0VZWT7p65gV1cprr9df/5JDsfazi+LXMPSb6K0dUqb5pw3dJUWQTqQttf/zzghe16738MnJDklLHZDtyDh/x14LwkXwuQZP9s/7L784BXJzmgTXsM8F1tnTvI6Avhfwf402pfiyrNmruG1I2quibJPwFPqarXJflB4FVJfpvRZYg/B/zahI/1ziSHAe9p37pVwCVt8gXAIcB1Sb7M6KsJT62qL4w9xFVtuXsBbwN+dWza0W131oJLqurVe/wflibkZaglqXPuGpKkzrlrSFpEknOBH9lp9Fuq6mXzyCMNwV1DktQ5dw1JUucsAknqnEUgSZ2zCCSpcxaBJHXu/wC1xqEU+D59ywAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = sns.countplot(x=\"RGI_CODE\", data=misplaced)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example plots "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARUAAAD8CAYAAABZ0jAcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/A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7HoIkAAagBrgWbcdGeNRv4b2PxToV9VVKcXnqmqziFQAvwPOI/mffUwmYL8yxqO+BYAjgYOBfuBJEVmuqk+SofcsE3IqqKjq8buzn4g0Ag8An1bV9SnHewh4yK1zEcngMdwngT+r6iCwVUT+DiwkeZaS+t+kEWjenfZ51K8hSxh2lqKqze7XXhG5h2RgHfMv6AR/iEnzAAABLklEQVTrVzPJ92jIbr9fblu86Nsm4K+q2u7Wexg4EHgyU+9ZRng9qJPpFzsOjlWTHEQ9Y4S6de7XGuAlYMEIda4B7nCXy4A1wAdIBuQ3gdm8N1C7b670y93uI/mHNSelLABMcZeDJC//Ls71frnlwwdqT82x38UaYAXJGwYBkmMvH8n2ezZqv736xuPwBn6MZCSPAq3Ao275f5EcE3kp5TX0Bt7rBok1wJKUYy0CbnCXy4HfkhxYWwNclVLvVOB1kneBvpZL/XLXjwGeG/b9yoDlJO8yrAa+j3uHIZf75ZYvBFa579etuA9/5ljfPuW+L6uA72TzPUv3ZU/UGmMyqtDu/hhjxpkFFWNMRllQMcZklAUVY0xGWVAxxmSUBRVjTEZZUDHGZJQFFWNMRv1/66kg35BmPnUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "i = 0\n",
    "dx = 0.1\n",
    "f, ax = plt.subplots(1, 1)\n",
    "rgi_sreg.loc[rgi_sreg.RGI_CODE == misplaced.iloc[i].RGI_CODE].plot(ax=ax, edgecolor='k', facecolor='C3');\n",
    "rgi_sreg.loc[rgi_sreg.RGI_CODE == misplaced.iloc[i].NEW_SREG].plot(ax=ax, edgecolor='k', facecolor='C2');\n",
    "misplaced.iloc[[i]].plot(ax=ax, edgecolor='k', facecolor='C1');\n",
    "plt.xlim(misplaced.iloc[i].CenLon-dx, misplaced.iloc[i].CenLon+dx)\n",
    "plt.ylim(misplaced.iloc[i].CenLat-dx, misplaced.iloc[i].CenLat+dx);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
